﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Alison.EFCore.Entity;

#nullable disable

namespace Alison.EFCore
{
    public partial class AlisonDbContext : DbContext
    {
        public AlisonDbContext()
        {
        }

        public AlisonDbContext(DbContextOptions<AlisonDbContext> options)
            : base(options)
        {
        }
         
        public virtual DbSet<Authitem> Authitems { get; set; }
        public virtual DbSet<Basic> Basics { get; set; }
        public virtual DbSet<Basictype> Basictypes { get; set; }
        public virtual DbSet<Group> Groups { get; set; }
        public virtual DbSet<Groupfunc> Groupfuncs { get; set; }
        public virtual DbSet<Groupuser> Groupusers { get; set; }
        public virtual DbSet<Menu> Menus { get; set; }
        public virtual DbSet<Mqttmessage> Mqttmessages { get; set; } 
        public virtual DbSet<User> Users { get; set; }
        public virtual DbSet<Userconfig> Userconfigs { get; set; }
        public virtual DbSet<Userlog> Userlogs { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseNpgsql("Host=127.0.0.1;Database=alison_db;Username=postgres;Password=postgres");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "Chinese (Simplified)_China.936");

            modelBuilder.Entity<AlisonUser>(entity =>
            {
                entity.HasKey(e => e.Iid)
                    .HasName("alison_user_pkey");

                entity.ToTable("alison_user");

                entity.Property(e => e.Iid)
                    .ValueGeneratedNever()
                    .HasColumnName("iid");

                entity.Property(e => e.Createby).HasColumnName("createby");

                entity.Property(e => e.Createtime).HasColumnName("createtime");

                entity.Property(e => e.Email)
                    .HasMaxLength(50)
                    .HasColumnName("email")
                    .IsFixedLength(true);

                entity.Property(e => e.Enabled).HasColumnName("enabled");

                entity.Property(e => e.Fullname)
                    .HasMaxLength(50)
                    .HasColumnName("fullname")
                    .IsFixedLength(true);

                entity.Property(e => e.Lastlogintime).HasColumnName("lastlogintime");

                entity.Property(e => e.Logincount).HasColumnName("logincount");

                entity.Property(e => e.Loginname)
                    .HasMaxLength(50)
                    .HasColumnName("loginname")
                    .IsFixedLength(true);

                entity.Property(e => e.Loginpwd).HasColumnName("loginpwd");

                entity.Property(e => e.Modifyby).HasColumnName("modifyby");

                entity.Property(e => e.Modifytime).HasColumnName("modifytime");

                entity.Property(e => e.Phone)
                    .HasMaxLength(50)
                    .HasColumnName("phone")
                    .IsFixedLength(true);

                entity.Property(e => e.Pwderrorcount).HasColumnName("pwderrorcount");

                entity.Property(e => e.Registertime).HasColumnName("registertime");
            });

            modelBuilder.Entity<Authitem>(entity =>
            {
                entity.ToTable("authitems");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Authcolor)
                    .HasMaxLength(255)
                    .HasColumnName("authcolor");

                entity.Property(e => e.Authkind)
                    .HasMaxLength(255)
                    .HasColumnName("authkind");

                entity.Property(e => e.Authname)
                    .HasMaxLength(255)
                    .HasColumnName("authname");

                entity.Property(e => e.Authvalue).HasColumnName("authvalue");
            });

            modelBuilder.Entity<Basic>(entity =>
            {
                entity.ToTable("basic");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Createby)
                    .HasMaxLength(255)
                    .HasColumnName("createby");

                entity.Property(e => e.Createdate)
                    .HasColumnType("date")
                    .HasColumnName("createdate");

                entity.Property(e => e.Datacode)
                    .HasMaxLength(255)
                    .HasColumnName("datacode");

                entity.Property(e => e.Englishname)
                    .HasMaxLength(255)
                    .HasColumnName("englishname");

                entity.Property(e => e.Lastupdate)
                    .HasColumnType("date")
                    .HasColumnName("lastupdate");

                entity.Property(e => e.Lastupdateby)
                    .HasMaxLength(255)
                    .HasColumnName("lastupdateby");

                entity.Property(e => e.Nativename)
                    .HasMaxLength(255)
                    .HasColumnName("nativename");

                entity.Property(e => e.Typecode)
                    .HasMaxLength(255)
                    .HasColumnName("typecode");
            });

            modelBuilder.Entity<Basictype>(entity =>
            {
                entity.ToTable("basictype");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Typecode)
                    .HasMaxLength(255)
                    .HasColumnName("typecode");

                entity.Property(e => e.Typename)
                    .HasMaxLength(255)
                    .HasColumnName("typename");
            });

            modelBuilder.Entity<Group>(entity =>
            {
                entity.ToTable("groups");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Groupcode)
                    .HasMaxLength(255)
                    .HasColumnName("groupcode");

                entity.Property(e => e.Groupname)
                    .HasMaxLength(255)
                    .HasColumnName("groupname");
            });

            modelBuilder.Entity<Groupfunc>(entity =>
            {
                entity.ToTable("groupfunc");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Auth).HasColumnName("auth");

                entity.Property(e => e.Groupcode)
                    .HasMaxLength(255)
                    .HasColumnName("groupcode");

                entity.Property(e => e.Menucode)
                    .HasMaxLength(255)
                    .HasColumnName("menucode");
            });

            modelBuilder.Entity<Groupuser>(entity =>
            {
                entity.ToTable("groupuser");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Account)
                    .HasMaxLength(255)
                    .HasColumnName("account");

                entity.Property(e => e.Groupcode)
                    .HasMaxLength(255)
                    .HasColumnName("groupcode");
            });

            modelBuilder.Entity<Menu>(entity =>
            {
                entity.ToTable("menus");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Menuauth).HasColumnName("menuauth");

                entity.Property(e => e.Menucaption)
                    .HasMaxLength(255)
                    .HasColumnName("menucaption");

                entity.Property(e => e.Menucode)
                    .HasMaxLength(255)
                    .HasColumnName("menucode");

                entity.Property(e => e.Menuname)
                    .HasMaxLength(255)
                    .HasColumnName("menuname");

                entity.Property(e => e.Menunamespace)
                    .HasMaxLength(255)
                    .HasColumnName("menunamespace");
            });

            modelBuilder.Entity<Mqttmessage>(entity =>
            {
                entity.ToTable("mqttmessages");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Clientip)
                    .HasMaxLength(32)
                    .HasColumnName("clientip");

                entity.Property(e => e.Messagetype)
                    .HasMaxLength(255)
                    .HasColumnName("messagetype");

                entity.Property(e => e.Payload).HasColumnName("payload");

                entity.Property(e => e.Sclientid)
                    .HasMaxLength(255)
                    .HasColumnName("sclientid");

                entity.Property(e => e.Sendtime)
                    .HasColumnType("date")
                    .HasColumnName("sendtime");

                entity.Property(e => e.Serverip)
                    .HasMaxLength(32)
                    .HasColumnName("serverip");

                entity.Property(e => e.Topic)
                    .HasMaxLength(255)
                    .HasColumnName("topic");
            });

            modelBuilder.Entity<Studenttemp>(entity =>
            {
                entity.HasKey(e => e.Sid)
                    .HasName("studenttemp_pkey");

                entity.ToTable("studenttemp");

                entity.Property(e => e.Sid).HasColumnName("sid");

                entity.Property(e => e.Adddate).HasColumnName("adddate");

                entity.Property(e => e.Address).HasColumnName("address");

                entity.Property(e => e.Sname).HasColumnName("sname");
            });

            modelBuilder.Entity<User>(entity =>
            {
                entity.ToTable("users");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Account)
                    .HasMaxLength(255)
                    .HasColumnName("account");

                entity.Property(e => e.Address)
                    .HasMaxLength(255)
                    .HasColumnName("address");

                entity.Property(e => e.Createtime)
                    .HasColumnType("date")
                    .HasColumnName("createtime");

                entity.Property(e => e.Email)
                    .HasMaxLength(255)
                    .HasColumnName("email");

                entity.Property(e => e.Flagadmin).HasColumnName("flagadmin");

                entity.Property(e => e.Flagonline)
                    .HasMaxLength(255)
                    .HasColumnName("flagonline");

                entity.Property(e => e.Islocked).HasColumnName("islocked");

                entity.Property(e => e.Lastlogintime)
                    .HasColumnType("date")
                    .HasColumnName("lastlogintime");

                entity.Property(e => e.Lastlogoutime)
                    .HasColumnType("date")
                    .HasColumnName("lastlogoutime");

                entity.Property(e => e.Logincounter).HasColumnName("logincounter");

                entity.Property(e => e.Password)
                    .HasMaxLength(255)
                    .HasColumnName("password");

                entity.Property(e => e.Tel)
                    .HasMaxLength(255)
                    .HasColumnName("tel");

                entity.Property(e => e.Username)
                    .HasMaxLength(255)
                    .HasColumnName("username");
            });

            modelBuilder.Entity<Userconfig>(entity =>
            {
                entity.ToTable("userconfig");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Account)
                    .HasMaxLength(255)
                    .HasColumnName("account");

                entity.Property(e => e.Expectedin).HasColumnName("expectedin");

                entity.Property(e => e.Expectedout).HasColumnName("expectedout");
            });

            modelBuilder.Entity<Userlog>(entity =>
            {
                entity.ToTable("userlog");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Content)
                    .HasMaxLength(255)
                    .HasColumnName("content");

                entity.Property(e => e.Createtime)
                    .HasMaxLength(500)
                    .HasColumnName("createtime");

                entity.Property(e => e.Username)
                    .HasMaxLength(255)
                    .HasColumnName("username");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
